<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1">
		<title>CRM</title>
		<link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/mui.min.css" th:href="@{/azxcrm/css/wap/mui.min.css}"/>
		<link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/mui.picker.min.css" th:href="@{/azxcrm/css/wap/mui.picker.min.css}"/>
		<link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/aui.css" th:href="@{/azxcrm/css/wap/aui.css}"/>
		<link rel="stylesheet" type="text/css" href="../static/azxcrm/css/wap/add_lesson.css" th:href="@{/azxcrm/css/wap/add_lesson.css}"/>
		<script src="../static/azxcrm/js/wap/mui.min.js" th:src="@{/azxcrm/js/wap/mui.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../static/azxcrm/js/wap/mui.picker.min.js" th:src="@{/azxcrm/js/wap/mui.picker.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../static/azxcrm/js/wap/city.data-3.js" th:src="@{/azxcrm/js/wap/city.data-3.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
		<script th:inline="javascript"> var ctx = [[@{/}]]; </script>
	</head>
	<body>
		<header class="aui-bar aui-bar-nav">
			 <a href="javascript:history.back(-1)"  class="aui-pull-left aui-btn">
	       		 <span class="iconfont icon-fanhui1">返回</span>
	    	</a>
		    <div class="aui-title">添加参课记录</div>
		</header>
		<section class="aui-grid aui-margin-b-15">
			<div class="aui-content aui-margin-b-15">
			    <ul class="aui-list aui-list-in">			       
					<li class="aui-list-item">
			            <div class="aui-list-item-inner">
			                <div class="aui-list-item-label">真实姓名：</div>
			                <div class="aui-list-item-input">
			                    <input type="text" name="attendCustName" placeholder="请输入真实姓名">
			                    <input type="hidden" th:value="${user.deptId}" name="deptId"> 
			                </div>
			            </div>
					</li>
					<li class="aui-list-item">
			            <div class="aui-list-item-inner">
			                <div class="aui-list-item-label">手机号码：</div>
			                <div class="aui-list-item-input">
			                    <input type="text" name="cellphoneNum" placeholder="请输入手机号码">
			                </div>
			            </div>
					</li>	
					<li class="aui-list-item">
			            <div class="aui-list-item-inner">
			                <div class="aui-list-item-label">年龄：</div>
			                <div class="aui-list-item-input">
			                    <input type="number" name="age" oninput="if(value.length>3)value=value.slice(0,3)" placeholder="请输入年龄">
			                </div>
			            </div>
					</li>
					<li class="aui-list-item" id="sex">
			            <div class="aui-list-item-inner">
			                <div class="aui-list-item-label">性别：</div>
			                <div class="aui-list-item-input">
			                    <input class="sex_fale" type="text" placeholder="请选择性别男/女">
			                    <input class="sex_value" type="hidden" name="sex">
			                </div>
			            </div>
					</li>
					<li class="aui-list-item" id="agent">
			            <div class="aui-list-item-inner">
			                <div class="aui-list-item-label">是否本人：</div>
			                <div class="aui-list-item-input">
			                    <input class="agent_dai" type="text" placeholder="本人/代咨询">
			                    <input class="agent_value" type="hidden" name="isOwnself">
			                </div>
			            </div>
					</li>
					<li class="aui-list-item" id="date">
			            <div class="aui-list-item-inner">
			                <div class="aui-list-item-label">参课时间：</div>
			                <div class="aui-list-item-input">
			                    <input class="add_lesson_time" type="text" placeholder="请选择参课时间" name="attendanceTime">
			                </div>
			            </div>
					</li>
			    </ul>
			</div>
		</section>
	</body>
</html>
		<footer class="aui-bar aui-bar-tab" id="footer">
		    <a type="button" id="toastBtn" onclick="add()" class="aui-bar-tab-item btn">                   
		        <div class="aui-bar-tab-label wait">确认提交</div>
		    </a>
	   </footer>
	</body>
</html>
<script>
	var sex=document.getElementById("sex");
	var agent=document.getElementById("agent");
	var data=document.getElementById("date");
	var sex_data= new mui.PopPicker();
			sex_data.setData([{
						value: '0',
						text: '男',
					}, {
						value: '1',
						text: '女',
					}
				])
		sex.addEventListener('tap', function() {
			sex_data.show(function(items) {
				document.getElementsByClassName('sex_fale')[0].value = items[0].text;
				document.getElementsByClassName('sex_value')[0].value = items[0].value;
				//返回 false 可以阻止选择框的关闭
				//return false;
			});
		}, false);
		var agent_data= new mui.PopPicker();
			agent_data.setData([{
						value: '0',
						text: '本人',
					}, {
						value: '1',
						text: '代咨询',
					}
				])
		agent.addEventListener('tap', function() {
			agent_data.show(function(items) {
				document.getElementsByClassName('agent_dai')[0].value = items[0].text;
				document.getElementsByClassName('agent_value')[0].value = items[0].value;
				//返回 false 可以阻止选择框的关闭
				//return false;
			});
		}, false);
		
		data.addEventListener('tap', function() {
			var picker = new mui.DtPicker({type:'date'});
		      picker.show(function(rs) {
		       document.getElementsByClassName('add_lesson_time')[0].value = rs.text;
		        picker.dispose();
		      });
		})
		
		function add(){
			var attendCustName=$("input[name='attendCustName']").val();
			
			var cellphoneNum=$("input[name='cellphoneNum']").val();
			
			var sexs=$("input[name='sex']").val();
		
			var age=$("input[name='age']").val();
			
			var isOwnself=$("input[name='isOwnself']").val();
			
			var agent_dai=$('.agent_dai').val();
			
			var attendanceTime=$("input[name='attendanceTime']").val();
			 
			var deptId=$("input[name='deptId']").val();
			var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
			if(attendCustName==''){
				 mui.toast("请输入姓名");
				 return false
			}else if(cellphoneNum==''){
				 mui.toast("请输入手机号码");
				 return false
			}else if(!myreg.test(cellphoneNum)){
				mui.toast("手机号码错误");		
				return false
			}else if(age==''){
				mui.toast("请输入年龄");
				return false
			}else if(sexs==''){
				mui.toast("请选择性别");
				return false
			}else if(agent_dai==''){
					mui.toast("请选择是否本人");
					return false
			}else if(attendanceTime==''){
				mui.toast("请选择参课时间");
				return false				
			}else{
				 $.ajax({
			            cache : true,
			            type : "POST",
			            url : ctx + "/wap/order/addCustomerAttendance",
			            data : {
							"attendCustName" : attendCustName,
							"cellphoneNum" : cellphoneNum,
							"sex" : sexs,
							"age" : age,
							"isOwnself" : isOwnself,
							"attendanceTime" : attendanceTime,
							"deptId" :　deptId
			            },
			            async : false,
			            error : function(request) {
			                mui.toast("系统错误");
			            },
			            success : function(data) {
			                if (data.code == 0) {
			                    mui.toast("添加成功!"); 
			                    $("#toastBtn").removeAttr("onclick");
			                    setTimeout(function(){
			                        window.location.href= ctx + "wap/order/myCustomerAttendance"},2200)
			                } else {
			                    mui.toast("添加失败!");
			                }
			            }
			        });	 
				}					
			}
</script>